package com.yiyuan.system.dao.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.yiyuan.common.base.BaseDao;
import com.yiyuan.system.dao.IResDao;
import com.yiyuan.system.model.PriResource;

@Repository("resDao")
public class ResDaoHbImpl extends BaseDao implements IResDao {
	public void add(PriResource priResource) {
		this.getHibernateTemplate().save(priResource);
	}

	public void update(PriResource priResource) {
		this.getHibernateTemplate().update(priResource);
	}

	public PriResource get(Integer resId) {
		return (PriResource) this.getHibernateTemplate()
				.get(PriResource.class, resId);
	}

	public void delete(PriResource priResource) {
		this.getHibernateTemplate().delete(priResource);
	}

	@SuppressWarnings("unchecked")
	public List<PriResource> findSubList(String resId) {
		Session session = this.getSession();
		Query query = session.createQuery("from PriResource where resPid=:resPid");
		query.setInteger("resPid", Integer.parseInt(resId));
		List<PriResource> list = query.list();
		return list;
	}
	@SuppressWarnings("unchecked")
	public List<PriResource> findList(){
		return this.getHibernateTemplate().find("from PriResource where resType='1'");
	}
}
